package com.bw.module_main.adapter

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.widget.TextView
import com.bw.module_device.R
import com.bw.module_device.entity.DeviceResult
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import java.text.DecimalFormat
/**
 * 智慧园区-01-设备管理-v1.1-吴熙-20250507
 */
class DeviceAdapter : BaseQuickAdapter<DeviceResult,BaseViewHolder>(R.layout.item_device) {
    override fun convert(holder: BaseViewHolder, item: DeviceResult) {
        holder.getView<TextView>(R.id.tv1).text = "项目名称/设备名称：${item.deviceName}"
        val view = holder.getView<TextView>(R.id.tv2)
        view.text = item.status
        val drawable = GradientDrawable()
        drawable.cornerRadius = 15f
        view.background = drawable
        if (item.status.contains("故障")){
            view.setTextColor(Color.parseColor("#F97C25"))
            drawable.setColor(Color.parseColor("#FFF1E3"))
        }else if (item.status.contains("正常")){
            view.setTextColor(Color.parseColor("#8DE1AE"))
            drawable.setColor(Color.parseColor("#EAFBF0"))
        }
        holder.getView<TextView>(R.id.tv3).text = "设备类型：${item.deviceType}"
        holder.getView<TextView>(R.id.tv4).text = "安装地点：${item.installationLocation}"
        val decimalFormat = DecimalFormat("##%")
        holder.getView<TextView>(R.id.tv5).text = "故障率：${decimalFormat.format(item.failureRate)}"


    }


}